package cc.rengu.redp.bizimpl.upmp.service.impl;
import cc.rengu.igas.bomp.facade.*;
import cc.rengu.igas.bomp.facade.bean.MchntAreaInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntFeeInfoBean;
import cc.rengu.igas.bomp.facade.bean.MchntInfoBean;
import cc.rengu.igas.bomp.facade.enums.BompMchntStatusEnum;
import cc.rengu.igas.bomp.facade.request.MchntAreaListQueryRequest;
import cc.rengu.igas.bomp.facade.request.MchntFeeListQueryRequest;
import cc.rengu.igas.bomp.facade.request.MchntInfoListQueryRequest;
import cc.rengu.igas.bomp.facade.response.MchntAreaListQueryResponse;
import cc.rengu.igas.bomp.facade.response.MchntFeeListQueryResponse;
import cc.rengu.igas.bomp.facade.response.MchntInfoListQueryResponse;
import cc.rengu.igas.momp.facade.*;
import cc.rengu.igas.momp.facade.base.Header;
import cc.rengu.igas.momp.facade.bean.*;
import cc.rengu.igas.momp.facade.request.*;
import cc.rengu.igas.momp.facade.response.*;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.redp.bizimpl.enums.BompTxnNumEnum;
import cc.rengu.redp.bizimpl.enums.MompTxnNumEnum;
import cc.rengu.redp.bizimpl.upmp.bean.CommissionAddMchntRequest;
import cc.rengu.redp.bizimpl.upmp.bean.CommissionInfo;
import cc.rengu.redp.bizimpl.upmp.bean.CommissionPublishRequest;
import cc.rengu.redp.bizimpl.upmp.bean.MarketManagerRequest;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpSysParam;
import cc.rengu.redp.bizimpl.upmp.service.CommissionMarketService;
import cc.rengu.redp.bizimpl.upmp.service.ICustomerMarketService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpBMchntBaseInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.DateUtils;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.common.utils.SortUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.*;

@Slf4j
@Service
public class CommissionMarketServiceImpl implements CommissionMarketService {

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62145",check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    private QueryMcListInfoService queryMcListInfoService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62145",check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    private EditMcDetailService editMcDetailService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62145",check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    private QueryMcDetailInfoService detailInfoService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62145",check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    private ManageMcService manageMcService;

//    @DubboReference(version = "2.2.0",url = "dubbo://172.17.100.9:62145",check = false)
    @DubboReference(version = "${dubbo.protocol.momp.version}", check = false)
    private PublishMcService publishMcService;

    @Autowired
    private IUpmpBMchntBaseInfoService iUpmpBMchntBaseInfoService;

    @Autowired(required = false)
    private MchntFeeTxnAmtLimitService mchntFeeTxnAmtLimitService;

    @Autowired(required = false)
    private QueryStatisticsService queryStatisticsService;

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

    //收银员那边的使用商圈
    @Autowired
    private ICustomerMarketService customerMarketService;


    /**
     * 商户手续费优惠营销活动列表查询
     *
     * @param queryRequest
     * @param reqDto
     * @return
     */
    public IPage<MchntFeeDiscountMcListInfoBean> findByPage(QueryRequest queryRequest, QueryMchntFeeDiscountMcListInfoRequest reqDto) throws RedpException {
        Result<QueryMchntFeeDiscountMcListInfoResponse> res = new Result<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
//        设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());
        reqDto.setPageIndex(String.valueOf(queryRequest.getPageNum()-1));
        reqDto.setPageSize(String.valueOf(queryRequest.getPageSize()));

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.FEEDISCOUNT_MC_LIST.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO011" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);
        try {
            log.info("查询商户手续费优惠营销活动列表 请求报文{}", JSON.toJSONString(reqDto));
            res = queryMcListInfoService.queryMchntFeeDiscountMcList(reqDto);
            log.info("查询商户手续费优惠营销活动列表 应答报文{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("商户手续费优惠营销活动列表查询时系统异常:[{}]", e);
            throw new RedpException("商户手续费优惠营销活动列表查询时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error("商户手续费优惠营销活动列表查询时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("商户手续费优惠营销活动列表查询时接口调用失败");
        }
        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("商户手续费优惠营销活动列表查询时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("商户手续费优惠营销活动列表查询时失败:" + res.getResult().getRespDesc());
        }
        // 应答
        Page<MchntFeeDiscountMcListInfoBean> page = new Page<>();
        List<MchntFeeDiscountMcListInfoBean> list = Lists.newArrayList();
        if (Common.isNotBlank(res) && org.apache.commons.collections4.CollectionUtils.isNotEmpty(res.getResult().getMcListInfo())) {
            list = res.getResult().getMcListInfo();
            page.setRecords(list);
            page.setTotal(Integer.parseInt(res.getResult().getTotalRows()));
        } else {
            log.info("商户手续费优惠营销活动列表查询时没有返回数据:result=[{}]", JSON.toJSONString(res.getResult()));
            page.setRecords(list);
            page.setTotal(0);
        }
        return page;
    }


    //修改方法
    @Override
    public Map<String, Object> setModel(String mcNo, String queryType, String queryRole) throws RedpException {
//        Map<String, Object> map =new HashMap<>();
//        QueryMchntFeeDiscountMcDetailInfoResponse respBean = this.getDetailData(mcNo, queryType, queryRole);
//        MchntFeeDiscountMcInfoBean entity = respBean.getMcInfoObj();
//        --
//        if ("1".equals(entity.getBeforeFlag()) && "0".equals(entity.getAfterFlag())) {
//            entity.setBudget(null);
//        }
//        if ("0".equals(entity.getStatPeriod())) {
//            entity.setQuantityLimit(null);
//            entity.setAmountLimit(null);
//            entity.setFeeLimit(null);
//        }
//        --
//        Date start = DateUtils.parseDate(entity.getMcStartDate(), DateUtils.FORMAT_YYYYMMDD);
//        Date end = DateUtils.parseDate(entity.getMcEndDate(), DateUtils.FORMAT_YYYYMMDD);
//        entity.setMcStartDate(DateUtils.formatDate(start, DateUtils.DEFAULT_DATE_FORMAT));
//        entity.setMcEndDate(DateUtils.formatDate(end, DateUtils.DEFAULT_DATE_FORMAT));
//        // 详情时特殊处理：前端使用的checkbox只有0和1。当存量商户达标条件为2-支持选定机构内所有有效商户时 也设置为checkbox=1
//        --
//        if ("2".equals(entity.getStockMchntFlag())) {
//            entity.setStockMchntFlag("1");
//        }
//        map.put("entity", entity);
//        List<String> orgList = new ArrayList<>();
//        List<McOrgInfoBean> orgInfoList = respBean.getOrgInfoList();
//        for (McOrgInfoBean orgBean : orgInfoList) {
//            orgList.add(orgBean.getOrgId());
//        }
//        map.put("orgList", JSON.toJSONString(orgList));
//        --
//        List<MchntFeeDiscountRuleInfoBean> ruleInfoList = respBean.getRuleInfoList();
//        if (null != ruleInfoList && ruleInfoList.size() > 0) {
//            map.put("discountPeriod", ruleInfoList.get(0).getDiscountPeriod());
//        }
//        map.put("rules", JSON.toJSONString(ruleInfoList));
//        map.put("merchantList", merchantList);
//        map.put("circleList", circleList);
//

        Map<String, Object> map =new HashMap<>();
        QueryMchntFeeDiscountMcDetailInfoResponse respBean = this.getDetailData(mcNo, queryType, queryRole);
        MchntFeeDiscountMcInfoBean mcInfoObj = respBean.getMcInfoObj();
        if ("1".equals(mcInfoObj.getBeforeFlag()) && "0".equals(mcInfoObj.getAfterFlag())) {
            mcInfoObj.setBudget(null);
        }
        if ("0".equals(mcInfoObj.getStatPeriod())) {
            mcInfoObj.setQuantityLimit(null);
            mcInfoObj.setAmountLimit(null);
            mcInfoObj.setFeeLimit(null);
        }
        if ("2".equals(mcInfoObj.getStockMchntFlag())) {
            mcInfoObj.setStockMchntFlag("1");
        }
        List<MchntFeeDiscountRuleInfoBean> ruleInfoList = respBean.getRuleInfoList();
        if (null != ruleInfoList && ruleInfoList.size() > 0) {
            map.put("discountPeriod", ruleInfoList.get(0).getDiscountPeriod());
        }
        Date start = DateUtils.parseDate(mcInfoObj.getMcStartDate(), DateUtils.FORMAT_YYYYMMDD);
        Date end = DateUtils.parseDate(mcInfoObj.getMcEndDate(), DateUtils.FORMAT_YYYYMMDD);
        mcInfoObj.setMcStartDate(DateUtils.formatDate(start, DateUtils.DEFAULT_DATE_FORMAT));
        mcInfoObj.setMcEndDate(DateUtils.formatDate(end, DateUtils.DEFAULT_DATE_FORMAT));
        map.put("mcNo", mcNo);
        // TODO  商户反显，目前老平台未应答这个数据，估计是数据量太大，后面可注释掉
        if(org.springframework.util.CollectionUtils.isEmpty(respBean.getMchntInfoList())){
            respBean.setMchntInfoList(new ArrayList<>());
        }
        List<McMchntInfoBean> mchntCircleList = customerMarketService.getMchntCircleList(mcNo, "-1", "-1");
        if (!org.springframework.util.CollectionUtils.isEmpty(mchntCircleList)) {
            respBean.getMchntInfoList().addAll(mchntCircleList);
        }
        QueryMcMerUserListRequest reqDto = new QueryMcMerUserListRequest();
        reqDto.setMcNo(mcNo);
        reqDto.setQueryType("0");
        reqDto.setQueryRole("00");
        IPage<McMchntInfoBean> mchntList = customerMarketService.getMchntList(reqDto, "-1", "-1");
        if (!org.springframework.util.CollectionUtils.isEmpty(mchntList.getRecords())) {
            respBean.getMchntInfoList().addAll(mchntList.getRecords());
        }
        map.put("datailData", JSONObject.toJSONString(respBean, SerializerFeature.WriteMapNullValue));
        return map;
    }

    //商户手续费优惠营销活动编辑
    @Override
    public void editSave(CommissionInfo entity) throws RedpException {
        //转换参数
        EditMchntFeeDiscountMcDetailRequest reqDto = getEditBean(entity);
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());

        reqDto.setMrctFilePath(entity.getMrctFilePath());
        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum("M00MO013");
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO013" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);
        Result<EditMchntFeeDiscountMcDetailResponse> res = new Result<>();
        try {
            log.info("商户手续费优惠营销活动编辑 请求报文：{}", JSON.toJSONString(reqDto));
            res = editMcDetailService.editMchntFeeDiscountMcDetail(reqDto);
            log.info("商户手续费优惠营销活动编辑 应答报文：{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("商户手续费优惠营销活动编辑时系统异常:[{}]", e);
            throw new RedpException("商户手续费优惠营销活动编辑时系统异常,请联系管理员");
        }

        if (null == res || null == res.getResult()) {
            log.error("商户手续费优惠营销活动编辑时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("商户手续费优惠营销活动编辑时接口调用失败");
        }

        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("商户手续费优惠营销活动编辑时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("商户手续费优惠营销活动编辑时失败:" + res.getResult().getRespDesc());
        }
    }


    /**
     * 转换管理时的请求对象
     *
     * @param entity
     * @return
     */
    private ManageMchntFeeDiscountMcRequest getManagerBean(MarketManagerRequest entity) {
        ManageMchntFeeDiscountMcRequest bean = new ManageMchntFeeDiscountMcRequest();
        bean.setMcNo(entity.getMcNo());
        bean.setOprType(entity.getOprType());
        bean.setOprContent(entity.getOprContent());
        bean.setQueryType(entity.getQueryType());
        bean.setQueryRole(entity.getQueryRole());
        return bean;
    }

    /**
     * 转换进行中活动新增商户的对象
     *
     * @param entity
     * @return
     */
    private AddMchntForToClientMcRequest getAddBean(CommissionAddMchntRequest entity) throws RedpException {
        AddMchntForToClientMcRequest bean = new AddMchntForToClientMcRequest();
        bean.setMcNo(entity.getMcNo());
        bean.setMcType(entity.getMcType());
        bean.setQueryType(entity.getQueryType());
        bean.setQueryRole(entity.getQueryRole());
        //商户信息
        //新增商户之后的商户商圈
        List<McMchntInfoBean> mchntInfoList = new ArrayList<>();
        if (StringUtils.isNotBlank(entity.getMerchantList())) {
            String merchantJson = StringEscapeUtils.unescapeHtml4(entity.getMerchantList());
            List<McMchntInfoBean> merchantList = JSONArray.parseArray(merchantJson, McMchntInfoBean.class);
            mchntInfoList.addAll(merchantList);
        }
        if (StringUtils.isNotBlank(entity.getCircleList())) {
            String circleJson = StringEscapeUtils.unescapeHtml4(entity.getCircleList());
            List<McMchntInfoBean> circletList = JSONArray.parseArray(circleJson, McMchntInfoBean.class);
            mchntInfoList.addAll(circletList);
        }
        //做个判断,entity.getMchntInfoOldList() 为空，说明是对客类营销活动新增，不允许删除原有的商户信息
        if (StringUtils.isBlank(entity.getMchntInfoOldList())) {
            bean.setMchntInfoList(mchntInfoList);
            return bean;
        }
        String mchOldJson = StringEscapeUtils.unescapeHtml4(entity.getMchntInfoOldList());
        //新增商户之前的商户商圈
        List<McMchntInfoBean> mchOldList = JSONArray.parseArray(mchOldJson, McMchntInfoBean.class);

        // 增加的商户
        List<McMchntInfoBean> addList = new ArrayList<>();
        // 删除的商户
        List<McMchntInfoBean> delList = new ArrayList<>();
        Map<String, McMchntInfoBean> oldObjMap = new HashMap<>();
        for (McMchntInfoBean mcMchntInfoBean : mchOldList) {
            oldObjMap.put(mcMchntInfoBean.getMchntNo(), mcMchntInfoBean);
        }
        for (McMchntInfoBean mcMchntInfoBean : mchntInfoList) {
            if (oldObjMap.containsKey(mcMchntInfoBean.getMchntNo())) {
                oldObjMap.remove(mcMchntInfoBean.getMchntNo());
            } else {
                mcMchntInfoBean.setOprType("I");
                addList.add(mcMchntInfoBean);
            }
        }
        for (String mchntNo : oldObjMap.keySet()) {
            McMchntInfoBean mcMchntInfoBean = oldObjMap.get(mchntNo);
            mcMchntInfoBean.setOprType("D");
            delList.add(oldObjMap.get(mchntNo));
        }

        if (CollectionUtils.isEmpty(addList) && CollectionUtils.isEmpty(delList)) {
            throw new RedpException("请输入要新增的商户或者商圈");
        }
        if (null == bean.getMchntInfoList()) {
            bean.setMchntInfoList(new ArrayList<>());
        }
        bean.getMchntInfoList().addAll(addList);
        bean.getMchntInfoList().addAll(delList);
        return bean;
    }

    //进行中活动新增商户
    @Override
    public OperationResult addmchntInfos(CommissionAddMchntRequest entity) {
        AddMchntForToClientMcRequest reqDto = new AddMchntForToClientMcRequest();
        try{
            reqDto = getAddBean(entity);
        }catch (RedpException se){
            return OperationResult.buildFailureResult("请输入要新增的商户");
        }

        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.TOCLIEENT_MC_ADD.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.TOCLIEENT_MC_ADD.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);

        Result<AddMchntForToClientMcResponse> res = new Result<>();
        try {
            log.info("进行中的活动添加商户 请求报文：{}", JSON.toJSONString(reqDto));
            res = editMcDetailService.addMchntForToClientMc(reqDto);
            log.info("进行中的活动添加商户 应答报文：{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("进行中的活动添加商户时系统异常:[{}]", e);
            //throw new ServiceException("进行中的活动添加商户时系统异常,请联系管理员");
            return OperationResult.buildFailureResult("进行中的活动添加商户时接口调用失败");
        }
        if (null == res || null == res.getResult()) {
            log.error("进行中的活动添加商户时接口调用失败:result=[{}]", JSON.toJSONString(res));
            //throw new ServiceException("进行中的活动添加商户时接口调用失败");
            return OperationResult.buildFailureResult("进行中的活动添加商户时接口调用失败");
        }

        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("进行中的活动添加商户时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            //throw new ServiceException("进行中的活动添加商户时失败:" + res.getResult().getRespDesc());
            return OperationResult.buildFailureResult("进行中的活动添加商户时失败:" + res.getResult().getRespDesc());
        }
        List<McMchntInfoBean> mchntInfoList = reqDto.getMchntInfoList();
        String oprType = "";
        for(McMchntInfoBean mcMchntInfoBean : mchntInfoList){
            oprType += mcMchntInfoBean.getOprType();
        }
        if(oprType.contains("I") && oprType.contains("D")){
            return OperationResult.buildSuccessResult("进行中的活动新增商户修改成功");
        }
        return OperationResult.buildSuccessResult("进行中的活动新增商户修改成功");
    }

    //商户优惠列表查询
    @Override
    public IPage<MchntQuotaInfoBean> findMchntPage(QueryMchntFeeTxnAmtLimitRequest reqDto, QueryRequest pageable) throws RedpException {
        Result<QueryMchntFeeTxnAmtLimitResponse> res = new Result<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());
        reqDto.setPageIndex(String.valueOf(pageable.getPageNum()));
        reqDto.setPageSize(String.valueOf(pageable.getPageSize()));



        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.MC_MER_AMT_LIMIT_QUERY.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "T00MO018" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);

        try {
            log.info("查询商户手续费优惠商户额度列表 请求报文{}", JSON.toJSONString(reqDto));
            res = mchntFeeTxnAmtLimitService.queryMchntFeeTxnAmtLimit(reqDto);
            log.info("查询商户手续费优惠商户额度列表 应答报文{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("查询商户手续费优惠商户额度列表查询时系统异常:[{}]", e);
            throw new RedpException("查询商户手续费优惠商户额度列表查询时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error("查询商户手续费优惠商户额度列表查询时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("查询商户手续费优惠商户额度列表查询时接口调用失败");
        }
        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("查询商户手续费优惠商户额度列表查询时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("查询商户手续费优惠商户额度列表查询时失败:" + res.getResult().getRespDesc());
        }
        if (null == res.getResult().getMchntQuotaInfoList()) {
            log.info("查询商户手续费优惠商户额度列表查询时没有返回数据:result=[{}]", JSON.toJSONString(res.getResult()));
            return null;
        }
        QueryMchntFeeTxnAmtLimitResponse result = res.getResult();
        Page<MchntQuotaInfoBean> page = new Page<>();
        SortUtil.handlePageSort(pageable, page, true);
//       得到营销优惠集合
        List<MchntQuotaInfoBean> mchntQuotaInfoList = Lists.newArrayList();
        if (Common.isNotBlank(result) && CollectionUtils.isNotEmpty(result.getMchntQuotaInfoList())) {
            mchntQuotaInfoList = result.getMchntQuotaInfoList();
            page.setRecords(mchntQuotaInfoList);
            String totalRows = result.getTotalRows();
            page.setTotal(Long.parseLong(totalRows));
        } else {
            page.setRecords(mchntQuotaInfoList);
            page.setTotal(0);
        }
        return page;
    }

    //变更商户优惠上限
    @Override
    public void changeAmtLimit(EditMchntFeeTxnAmtLimitRequest reqDto) throws RedpException {
        Result<EditMchntFeeTxnAmtLimitResponse> res = new Result<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.MC_MER_AMT_LIMIT_EDIT.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO040" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);
        try {
            log.info("商户当前周期手续费优惠限额修改 请求报文{}", JSON.toJSONString(reqDto));
            res = mchntFeeTxnAmtLimitService.editMchntFeeTxnAmtLimit(reqDto);
            log.info("商户当前周期手续费优惠限额修改 应答报文{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("商户当前周期手续费优惠限额修改时系统异常:[{}]", e);
            throw new RedpException("商户当前周期手续费优惠限额修改时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error("商户当前周期手续费优惠限额修改时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("商户当前周期手续费优惠限额修改接口调用失败");
        }
        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("商户当前周期手续费优惠限额修改时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("商户当前周期手续费优惠限额修改时失败:" + res.getResult().getRespDesc());
        }
    }

    //商户手续费优惠额度列表查询
    @Override
    public IPage<MchntFeeDiscountInfoBean> findMchntLimitListPage(QueryMchntFeeDiscountLimitRequest reqDto, QueryRequest pageable) throws RedpException {
        Result<QueryMchntFeeDiscountLimitResponse> res = new Result<>();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setPageIndex(String.valueOf(pageable.getPageNum()));
        reqDto.setPageSize(String.valueOf(pageable.getPageSize()));

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.MC_MER_FEE_DIS_LIMIT_QUERY.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "T00MO019" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);
        try {
            log.info("商户当前周期剩余优惠额度查询 请求报文{}", JSON.toJSONString(reqDto));
            res = queryStatisticsService.queryMchntFeeDiscountLimit(reqDto);
            log.info("商户当前周期剩余优惠额度查询 应答报文{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("商户当前周期剩余优惠额度查询时系统异常:[{}]", e);
            throw new RedpException("查商户当前周期剩余优惠额度查询时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error("商户当前周期剩余优惠额度查询时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("商户当前周期剩余优惠额度查询时接口调用失败");
        }
        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("商户当前周期剩余优惠额度查询时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("商户当前周期剩余优惠额度查询时失败:" + res.getResult().getRespDesc());
        }
        if (null == res.getResult().getMchntFeeDiscountInfoBeanList()) {
            log.info("商户当前周期剩余优惠额度查询时没有返回数据:result=[{}]", JSON.toJSONString(res.getResult()));
            return null;
        }
        QueryMchntFeeDiscountLimitResponse result = res.getResult();
        Page<MchntFeeDiscountInfoBean> page = new Page<>();
        SortUtil.handlePageSort(pageable, page, true);
//       得到营销优惠集合
        List<MchntFeeDiscountInfoBean> mchntFeeDiscountInfoBeanList = Lists.newArrayList();
        if (Common.isNotBlank(result) && CollectionUtils.isNotEmpty(result.getMchntFeeDiscountInfoBeanList())) {
            mchntFeeDiscountInfoBeanList = result.getMchntFeeDiscountInfoBeanList();
            page.setRecords(mchntFeeDiscountInfoBeanList);
            String totalRows = result.getTotalRows();
            page.setTotal(Long.parseLong(totalRows));
        } else {
            page.setRecords(mchntFeeDiscountInfoBeanList);
            page.setTotal(0);
        }
        return page;
    }

    /**
     * 转换编辑的对象
     *
     * @param entity
     * @return
     */
    private EditMchntFeeDiscountMcDetailRequest getEditBean(CommissionInfo entity) {
        EditMchntFeeDiscountMcDetailRequest bean = new EditMchntFeeDiscountMcDetailRequest();
        MchntFeeDiscountMcInfoBean mcInfoBean = new MchntFeeDiscountMcInfoBean();
        //请求报文参数
        bean.setOprType(entity.getOprType());
        bean.setQueryType(entity.getQueryType());
        bean.setQueryRole(entity.getQueryRole());
        mcInfoBean.setMcNo(entity.getMcNo());
        mcInfoBean.setMcName(entity.getMcName());
        mcInfoBean.setDepositMonNum(entity.getDepositMonNum());
        mcInfoBean.setMcType("20");//营销活动类型
        mcInfoBean.setMcStatus(entity.getMcStatus());
        mcInfoBean.setNewMchntAmountType(entity.getNewMchntAmountType());
        //日期可能需要转换格式
        if (StringUtils.isNotBlank(entity.getMcStartDate())) {
            mcInfoBean.setMcStartDate(entity.getMcStartDate().replaceAll("-", ""));
        }
        if (StringUtils.isNotBlank(entity.getMcEndDate())) {
            mcInfoBean.setMcEndDate(entity.getMcEndDate().replaceAll("-", ""));
        }
        String discountPeriod = null;
        String stockMchntFlag = entity.getStockMchntFlag(); //存量商户达标条件
        String stockMchntType = entity.getStockMchntType(); //存量商户支持类型
        if ("1".equals(stockMchntFlag)) {
            // 如果指定商户和商圈都未选择，stockMchntFlag上送2-支持选定机构内所有有效商户
            if (entity.getCircleList()!=null && entity.getCircleList()!=null) {
                mcInfoBean.setStockMchntFlag("2");
            } else {
                mcInfoBean.setStockMchntFlag(stockMchntFlag);
            }
            mcInfoBean.setStockMchntType(stockMchntType);
            if ("1".equals(stockMchntType)) {
                mcInfoBean.setEffectiveLimit(entity.getEffectiveLimitTranNum());
                discountPeriod = entity.getDiscoutPeriodTranNum();
            } else if ("2".equals(stockMchntType)) {
                mcInfoBean.setEffectiveLimit(entity.getEffectiveLimitTranMoney());
                discountPeriod = entity.getDiscoutPeriodTranMoney();
            } else if ("3".equals(stockMchntType)) {
                mcInfoBean.setEffectiveLimit("0");
                discountPeriod = entity.getDiscoutPeriodFeeMoney();
            } else {
                mcInfoBean.setEffectiveLimit("0");
            }
        } else {
            mcInfoBean.setStockMchntFlag("0");
        }

        String newMchntFlag = entity.getNewMchntFlag(); //新增商户支持标志
        if ("1".equals(newMchntFlag)) {
            mcInfoBean.setNewMchntFlag(newMchntFlag);
            mcInfoBean.setNewMchntPeriod(entity.getNewMchntPeriod());
            mcInfoBean.setNewMchntAmountLimit(entity.getNewMchntAmountLimit());
            mcInfoBean.setPostponeFlag("1".equals(entity.getPostponeFlag()) ? "1" : "0");
        } else {
            mcInfoBean.setNewMchntFlag("0");
        }
        String beforeFlag = (StringUtils.isEmpty(entity.getBeforeFlag()) || "1".equals(entity.getBeforeFlag())) ? "1" : "0";//达标前手续费优惠规则
        String afterFlag = entity.getAfterFlag();//达标后手续费优惠规则
        mcInfoBean.setBeforeFlag(beforeFlag);
        mcInfoBean.setAfterFlag(afterFlag);
        if ("1".equals(beforeFlag) && "0".equals(afterFlag)) {
            mcInfoBean.setBudget("0");
        } else {
            mcInfoBean.setBudget(entity.getBudget());
        }
        String statPeriod = entity.getStatPeriod();
        if (StringUtils.isBlank(statPeriod)) {
            mcInfoBean.setTerminationFlag("0");
            mcInfoBean.setStatPeriod("0");
            mcInfoBean.setQuantityLimit("0");
            mcInfoBean.setAmountLimit("0");
            mcInfoBean.setFeeLimit("0");
        } else {
            mcInfoBean.setTerminationFlag("1");
            mcInfoBean.setStatPeriod(entity.getStatPeriod());
            mcInfoBean.setQuantityLimit(entity.getQuantityLimit());
            mcInfoBean.setAmountLimit(entity.getAmountLimit());
            mcInfoBean.setFeeLimit(entity.getFeeLimit());
        }
        mcInfoBean.setBudgetRechargeMethod("1"); //预算充值方式
        mcInfoBean.setAuditStatus(entity.getAuditStatus());
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        mcInfoBean.setInstId(user.getInstId());//机构编码
        if (StringUtils.isBlank(entity.getMcNo())) {
            //为空表示新增,不为空表示修改
            mcInfoBean.setOprId(user.getId());//创建人
            mcInfoBean.setCreateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT));
        } else {
            mcInfoBean.setOprId(entity.getOprId());//创建人
            mcInfoBean.setCreateTime(entity.getCreateTime());
            mcInfoBean.setLastOprId(user.getId());
            mcInfoBean.setUpdateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT));
        }
        //活动支持的商户类型
        mcInfoBean.setAvySprtMrctTyp(entity.getSupportTypeStr());
        bean.setMcInfoObj(mcInfoBean);
        //机构信息
        //String orgInfoJson = StringEscapeUtils.unescapeHtml4(entity.getOrgInfoList());
        //List<McOrgInfoBean> orgInfoList = JSONArray.parseArray(orgInfoJson, McOrgInfoBean.class);
        bean.setOrgInfoList(entity.getOrgInfoList());

        //---------商户  商圈
        List<McMchntInfoBean> mcMchntList = new ArrayList<>();
        mcMchntList.addAll(entity.getMerchantList());
        mcMchntList.addAll(entity.getCircleList());
        bean.setMchntInfoList(mcMchntList);

        //规则信息
        if ("1".equals(stockMchntFlag) && entity.getRuleInfoList().size()>0) {
            List<MchntFeeDiscountRuleInfoBean> ruleInfoList = entity.getRuleInfoList();
            int i = 1;
            for (MchntFeeDiscountRuleInfoBean ruleInfoBean : ruleInfoList) {
                ruleInfoBean.setRuleIndex(String.valueOf(i));
                ruleInfoBean.setDiscountPeriod(discountPeriod);
                if (i == ruleInfoList.size() && StringUtils.isBlank(ruleInfoBean.getCriteriaCelling())) {
                    ruleInfoBean.setCriteriaCelling("99999999999999999.99");
                }
                i++;
            }

        }
        bean.setRuleInfoList(entity.getRuleInfoList());
        //产品信息
        List<McProductInfoBean> productInfoList = new ArrayList<>();
        List<String> upLineProduce = entity.getUpLineProduce();
        List<String> onLineProduce = entity.getOnLineProduce();
        if (null != upLineProduce && upLineProduce.size() > 0) {
            for (String code : upLineProduce) {
                McProductInfoBean infoBean = new McProductInfoBean();
                infoBean.setBizProdCode(code);
                productInfoList.add(infoBean);
            }
        }
        if (null != onLineProduce && onLineProduce.size() > 0) {
            for (String code : onLineProduce) {
                McProductInfoBean infoBean = new McProductInfoBean();
                infoBean.setBizProdCode(code);
                productInfoList.add(infoBean);
            }
        }
        bean.setProductInfoList(productInfoList);
        return bean;
    }

    /**
     * 根据活动编号查询活动详情
     *
     * @param mcNo
     * @return
     */
    public QueryMchntFeeDiscountMcDetailInfoResponse getDetailData(String mcNo, String queryType, String queryRole) throws RedpException {
        QueryMchntFeeDiscountMcDetailInfoRequest reqDto = new QueryMchntFeeDiscountMcDetailInfoRequest();
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());

        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());
        reqDto.setQueryType(queryType);
        reqDto.setQueryRole(queryRole);
        reqDto.setMcNo(mcNo);

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum("M00MO012");
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO012" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);
        Result<QueryMchntFeeDiscountMcDetailInfoResponse> res;
        try {
            log.info("查询营销活动详情 请求报文：{}", JSON.toJSONString(reqDto));
            res = detailInfoService.queryMchntFeeDiscountMcDetailInfo(reqDto);
            log.info("查询营销活动详情 应答报文：{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("查询营销活动详情时系统异常:[{}]", e);
            throw new RedpException("查询营销活动详情时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error("查询营销活动详情时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw  new RedpException("查询营销活动详情时接口调用失败");
        }
        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("查询营销活动详情时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw  new RedpException("查询营销活动详情时失败:" + res.getResult().getRespDesc());
        }
        return res.getResult();
    }

    /**
     * 根据orgcode获取固定长度14位的orgCode
     * 超过14位截取前14位
     * 不够14位前面补0
     * @param orgCode
     * @return
     */
    private String getOrgCode(String orgCode) {
        if (orgCode.length() >= 14) {
            return orgCode.substring(0, 14);
        }
        int length = orgCode.length();
        StringBuffer sb = null;
        while (length < 14) {
            sb = new StringBuffer();
            sb.append("0").append(orgCode);
            orgCode = sb.toString();
            length = orgCode.length();
        }
        return orgCode;
    }

    /**
     * 查询商户信息
     *
     * @param user
     * @param request
     * @param traceNo
     * @return
     */
    public Map<String, Object> queryMcNoList(UpmpUserInfoVO user, MchntInfoListQueryRequest request, String traceNo) {
        MchntInfoListQueryRequest req = new MchntInfoListQueryRequest();
        int pageIndex = 0;
        int pageSize = 50000;
        req.setMchntNo(request.getMchntNo());
        req.setMchntName(request.getMchntName());
        req.setMchntArea(request.getMchntArea());
        req.setPageIndex(pageIndex);
        req.setPageSize(pageSize);
        req.setMchntStatus(BompMchntStatusEnum.NORMAL.getType());
        req.setUserId(user.getId());
        MchntInfoListQueryResponse resp = null;
        try {
            resp = iUpmpBMchntBaseInfoService.mchntInfoListQuery(user.getInstId(), user, req, traceNo);
        } catch (RedpException e) {
            log.error("查询失败", e);
            return null;
        }
        Map<String, Object> maps = new HashMap<>();
        if (Common.isNotBlank(resp)) {
            List<MchntInfoBean> list = resp.getMchntInfoList();

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map = new HashMap<>();
                List<Object> rst = new ArrayList<>();
                for (MchntInfoBean mchnt : list) {

                    map = new HashMap<String, String>();
                    map.put("id", mchnt.getMchntNo());
                    map.put("name", mchnt.getMchntName());
                    map.put("orgId", mchnt.getSignInstId());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("more", false);
                maps.put("totalPage", resp.getTotalPage());
                maps.put("totalRows", resp.getTotalRows());
            }
        }
        return maps;
    }

    /**
     * 查询商圈信息
     *
     * @param user
     * @param request
     * @param bompQueryService
     * @param traceNo
     * @return
     */
    public Map<String, Object> queryMchntAreaList(UpmpUserInfoVO user, MchntAreaListQueryRequest request, BompMchntQueryService bompQueryService, String traceNo) {
        MchntAreaListQueryRequest req = new MchntAreaListQueryRequest();
        int pageIndex = 0;
        int pageSize = Integer.parseInt(BusinessContainer.ECP_PAGE_MAXROWS);
        req.setMchntArea(request.getMchntArea());
        req.setMchntAreaName(request.getMchntAreaName());
        req.setPageIndex(pageIndex);
        req.setPageSize(pageSize);
        req.setUserId(user.getId());
        MchntAreaListQueryResponse resp = null;
        try {
            resp = iUpmpBMchntBaseInfoService.mchntAreaListQuery(user.getInstId(), user, req, bompQueryService, traceNo);
        } catch (RedpException e) {
            log.error("查询失败", e);
            return null;
        }
        Map<String, Object> maps = new HashMap<>();
        if (Common.isNotBlank(resp)) {
            List<MchntAreaInfoBean> list = resp.getMchntAreaInfoList();

            if (CollectionUtils.isNotEmpty(list)) {
                Map<String, String> map;
                List<Object> rst = new ArrayList<>();
                for (MchntAreaInfoBean area : list) {

                    map = new HashMap<>();
                    map.put("id", area.getMchntArea());
                    map.put("name", area.getMchntAreaName());
                    map.put("orgId", area.getSignInstId());
                    rst.add(map);
                }
                maps.put("results", rst);
                maps.put("more", false);
                maps.put("totalPage", resp.getTotalPage());
                maps.put("totalRows", resp.getTotalRows());
            }
        }
        return maps;
    }

    /**
     * 校验是否是特殊费率商户
     *
     * @param user
     * @param mchntNo
     * @param bompQueryService
     * @param traceNo
     * @return
     */
    public Boolean checkFeeMchnt(UpmpUserInfoVO user, String mchntNo, BompMchntQueryService bompQueryService, String traceNo) {
        MchntFeeListQueryRequest req = new MchntFeeListQueryRequest();
        req.setMchntNo(mchntNo);
        req.setUserId(user.getId());
        MchntFeeListQueryResponse resp = this.mchntFeeListQuery(user.getInstId(), user, req, bompQueryService, traceNo);
        boolean isFeeMchntFlag = false;
        if (Common.isNotBlank(resp)) {
            List<MchntFeeInfoBean> list = resp.getMchntFeeInfoBeanList();

            if (CollectionUtils.isNotEmpty(list)) {
                for (MchntFeeInfoBean mchnt : list) {
                    if ("0".equals(mchnt.getFeeInputMode())) {
                        isFeeMchntFlag = true;
                    }
                }
            }
        }
        return isFeeMchntFlag;
    }

    /**
     * 商户费率列表查询
     */
    public MchntFeeListQueryResponse mchntFeeListQuery(String instId, UpmpUserInfoVO user, MchntFeeListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) {
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntFeeListQuery.getType(), instId, null));
        req.setUserId(user.getId());

        try {
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));

            cc.rengu.igas.bomp.facade.result.Result<MchntFeeListQueryResponse> response = bompQueryService.mchntFeeListQuery(req);
            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                MchntFeeListQueryResponse resp = response.getResult();
                // 返回码：00000000-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易成功");
                    return resp;
                } else {
                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易失败");
                    return null;
                }
            } else {
                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易没有获得返回信息");
                return null;
            }
        } catch (Exception e) {
            // TODO: handle exception
            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new RedpException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易出现异常");
            return null;
        }
    }

    /**
     * 商户手续费营销活动的管理，包括删除草稿、审核通过及退回
     *
     * @param entity
     */
    public void manageMchntFeeDiscountMc(MarketManagerRequest entity) throws RedpException {
        ManageMchntFeeDiscountMcRequest reqDto = getManagerBean(entity);
        // 获取当前登录用户信息
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String orgCode = getOrgCode(user.getOrgCode());

        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum(MompTxnNumEnum.FEEDISCOUNT_MC_MANAGER.getType());
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.FEEDISCOUNT_MC_MANAGER.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);

        Result<ManageMchntFeeDiscountMcResponse> res = new Result<>();
        try {
            log.info(MompTxnNumEnum.FEEDISCOUNT_MC_MANAGER.getDesc() + " 请求报文：{}", JSON.toJSONString(reqDto));
            res = manageMcService.manageMchntFeeDiscountMc(reqDto);
            log.info(MompTxnNumEnum.FEEDISCOUNT_MC_MANAGER.getDesc() + " 应答报文：{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error(entity.getMsg() + "时系统异常:[{}]", e);
            throw new RedpException(entity.getMsg() + "时系统异常,请联系管理员");
        }
        if (null == res || null == res.getResult()) {
            log.error(entity.getMsg() + "时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException(entity.getMsg() + "时接口调用失败");
        }

        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error(entity.getMsg() + "时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException(entity.getMsg() + "时失败:" + res.getResult().getRespDesc());
        }
    }

    /**
     * 商户手续费发布
     *
     * @param entity
     */
    @Override
    public void publishMchntFeeDiscountMc(CommissionPublishRequest entity, String msg) throws RedpException {
        PublishMchntFeeDiscountMcRequest reqDto = getPublishBean(entity);
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String skipPub = "";
        // 调用营销打款接口
        this.setModel(entity.getMcNo(), entity.getQueryType(), entity.getQueryRole());
        UpmpSysParam dict=upmpSysParamService.findByPrimaryKey("skipPub",user.getInstId(),null);
        if(Common.isNotBlank(dict)){
            skipPub = dict.getPrimaryValue();
        }
        // 达标后的交易通过手续费实时优惠营销,勾选了此选项，预算为0，故无需调用打款接口
        if (!"1".equals(skipPub)
                && StringUtils.isNotBlank(entity.getBudget()) &&
                !"0".equals(entity.getBudget())
                && "0".equals(entity.getOprType())) {
            OperationResult result = customerMarketService.mompPayment(entity.getMcNo(), reqDto.getAcctInfoObk(), user, entity.getBudget());
            if (!OperationResult.SUCCESS.equals(result.getCode())) {
                log.error("调用营销打款接口失败");
                throw new RedpException("调用营销打款接口失败，请联系管理员");
            }
        }
        //设置入参
        reqDto.setQueryId(user.getId());
        reqDto.setQueryOrgId(user.getOrgCode());

        //设置报文头
        Header header = new Header();
        header.setVersion(BusinessContainer.BOMP_VERSION);
        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
        header.setTxnNum("M00MO015");
        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
        header.setInstId(user.getInstId());
        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
        header.setTraceNo(user.getInstId().substring(0, 3) + user.getOrgCode() + "M00MO015" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
        reqDto.setHeader(header);

        Result<PublishMchntFeeDiscountMcResponse> res = new Result<>();
        try {
            log.info("商户手续费营销活动" + msg + " 请求报文：{}", JSON.toJSONString(reqDto));
            res = publishMcService.publishMchntFeeDiscountMc(reqDto);
            log.info("商户手续费营销活动" + msg + "  应答报文：{}", JSON.toJSONString(res));
        } catch (Exception e) {
            log.error("商户手续费营销活动" + msg + "时系统异常:[{}]", e);
            throw new  RedpException("商户手续费营销活动" + msg + "时系统异常,请联系管理员");
        }

        if (null == res || null == res.getResult()) {
            log.error("商户手续费营销活动" + msg + "时接口调用失败:result=[{}]", JSON.toJSONString(res));
            throw new RedpException("商户手续费营销活动" + msg + "时接口调用失败");
        }

        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
            log.error("商户手续费营销活动" + msg + "时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
            throw new RedpException("商户手续费营销活动" + msg + "时失败:" + res.getResult().getRespDesc());
        }
    }

    /**
     * 转换发布时的请求对象
     *
     * @param entity
     * @return
     */
    private PublishMchntFeeDiscountMcRequest getPublishBean(CommissionPublishRequest entity) {
        PublishMchntFeeDiscountMcRequest bean = new PublishMchntFeeDiscountMcRequest();
        bean.setMcNo(entity.getMcNo());
        bean.setOprType(entity.getOprType());
        bean.setOprContent(entity.getOprContent());
        bean.setQueryType(entity.getQueryType());
        bean.setQueryRole(entity.getQueryRole());
        bean.setAcctInfoObk(entity);
        return bean;
    }


    //    /**
//     * 商户优惠列表查询
//     *
//     * @param reqDto
//     * @param pageable
//     * @return
//     */
//    public Page<MchntQuotaInfoBean> findMchntPage(QueryMchntFeeTxnAmtLimitRequest reqDto, Pageable pageable) {
//        Result<QueryMchntFeeTxnAmtLimitResponse> res = new Result<>();
//        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
//        String orgCode = getOrgCode(user.getOrgCode());
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//        reqDto.setPageIndex(String.valueOf(pageable.getPageNumber()));
//        reqDto.setPageSize(String.valueOf(pageable.getPageSize()));
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum(MompTxnNumEnum.MCHNTFEE_DISCOUNT_STAT.getType());
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "T00MO018" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//        try {
//            log.info("查询商户手续费优惠商户额度列表 请求报文{}", JSON.toJSONString(reqDto));
//            res = mchntFeeTxnAmtLimitService.queryMchntFeeTxnAmtLimit(reqDto);
//            log.info("查询商户手续费优惠商户额度列表 应答报文{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("查询商户手续费优惠商户额度列表查询时系统异常:[{}]", e);
//            throw new ServiceException("查询商户手续费优惠商户额度列表查询时系统异常,请联系管理员");
//        }
//        if (null == res || null == res.getResult()) {
//            log.error("查询商户手续费优惠商户额度列表查询时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("查询商户手续费优惠商户额度列表查询时接口调用失败");
//        }
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("查询商户手续费优惠商户额度列表查询时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("查询商户手续费优惠商户额度列表查询时失败:" + res.getResult().getRespDesc());
//        }
//        if (null == res.getResult().getMchntQuotaInfoList()) {
//            log.info("查询商户手续费优惠商户额度列表查询时没有返回数据:result=[{}]", JSON.toJSONString(res.getResult()));
//            return new PageImpl<MchntQuotaInfoBean>(new ArrayList<MchntQuotaInfoBean>(), pageable, Integer.parseInt(res.getResult().getTotalRows()));
//        }
//
//        return new PageImpl<MchntQuotaInfoBean>(res.getResult().getMchntQuotaInfoList(), pageable, Integer.parseInt(res.getResult().getTotalRows()));
//
//    }
//
//    /**
//     * 商户手续费优惠额度列表查询
//     *
//     * @param reqDto
//     * @param pageable
//     * @return
//     */
//    public Page<MchntFeeDiscountInfoBean> findMchntLimitListPage(QueryMchntFeeDiscountLimitRequest reqDto, Pageable pageable) {
//        Result<QueryMchntFeeDiscountLimitResponse> res = new Result<>();
//        User user = AuthContextHolder.findAuthUser();
//        String orgCode = getOrgCode(user.getOrgCode());
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setPageIndex(String.valueOf(pageable.getPageNumber()));
//        reqDto.setPageSize(String.valueOf(pageable.getPageSize()));
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum(MompTxnNumEnum.MC_MER_FEE_DIS_LIMIT_QUERY.getType());
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "T00MO019" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//        try {
//            log.info("商户当前周期剩余优惠额度查询 请求报文{}", JSON.toJSONString(reqDto));
//            res = queryStatisticsService.queryMchntFeeDiscountLimit(reqDto);
//            log.info("商户当前周期剩余优惠额度查询 应答报文{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("商户当前周期剩余优惠额度查询时系统异常:[{}]", e);
//            throw new ServiceException("查商户当前周期剩余优惠额度查询时系统异常,请联系管理员");
//        }
//        if (null == res || null == res.getResult()) {
//            log.error("商户当前周期剩余优惠额度查询时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("商户当前周期剩余优惠额度查询时接口调用失败");
//        }
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("商户当前周期剩余优惠额度查询时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("商户当前周期剩余优惠额度查询时失败:" + res.getResult().getRespDesc());
//        }
//        if (null == res.getResult().getMchntFeeDiscountInfoBeanList()) {
//            log.info("商户当前周期剩余优惠额度查询时没有返回数据:result=[{}]", JSON.toJSONString(res.getResult()));
//            return new PageImpl<MchntFeeDiscountInfoBean>(new ArrayList<MchntFeeDiscountInfoBean>(), pageable, Integer.parseInt(res.getResult().getTotalRows()));
//        }
//
//        return new PageImpl<MchntFeeDiscountInfoBean>(res.getResult().getMchntFeeDiscountInfoBeanList(), pageable, Integer.parseInt(res.getResult().getTotalRows()));
//
//    }
//
//    /**
//     * 变更商户优惠上限
//     *
//     * @param reqDto
//     * @return
//     */
//    public void changeAmtLimit(EditMchntFeeTxnAmtLimitRequest reqDto) {
//        Result<EditMchntFeeTxnAmtLimitResponse> res = new Result<>();
//        User user = AuthContextHolder.findAuthUser();
//        String orgCode = getOrgCode(user.getOrgCode());
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum(MompTxnNumEnum.MC_MER_AMT_LIMIT_EDIT.getType());
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO040" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//        try {
//            log.info("商户当前周期手续费优惠限额修改 请求报文{}", JSON.toJSONString(reqDto));
//            res = mchntFeeTxnAmtLimitService.editMchntFeeTxnAmtLimit(reqDto);
//            log.info("商户当前周期手续费优惠限额修改 应答报文{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("商户当前周期手续费优惠限额修改时系统异常:[{}]", e);
//            throw new ServiceException("商户当前周期手续费优惠限额修改时系统异常,请联系管理员");
//        }
//        if (null == res || null == res.getResult()) {
//            log.error("商户当前周期手续费优惠限额修改时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("商户当前周期手续费优惠限额修改接口调用失败");
//        }
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("商户当前周期手续费优惠限额修改时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("商户当前周期手续费优惠限额修改时失败:" + res.getResult().getRespDesc());
//        }
//    }
//

//
//    /**
//     * 商户手续费优惠营销活动编辑
//     *
//     * @param entity
//     */
//    public void editSave(CommissionInfo entity) {
//        //转换参数
//        EditMchntFeeDiscountMcDetailRequest reqDto = getEditBean(entity);
//        User user = AuthContextHolder.findAuthUser();
//        String orgCode = getOrgCode(user.getOrgCode());
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//
//        reqDto.setMrctFilePath(entity.getMrctFilePath());
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum("M00MO013");
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO013" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//        Result<EditMchntFeeDiscountMcDetailResponse> res = new Result<>();
//        try {
//            log.info("商户手续费优惠营销活动编辑 请求报文：{}", JSON.toJSONString(reqDto));
//            res = editMcDetailService.editMchntFeeDiscountMcDetail(reqDto);
//            log.info("商户手续费优惠营销活动编辑 应答报文：{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("商户手续费优惠营销活动编辑时系统异常:[{}]", e);
//            throw new ServiceException("商户手续费优惠营销活动编辑时系统异常,请联系管理员");
//        }
//
//        if (null == res || null == res.getResult()) {
//            log.error("商户手续费优惠营销活动编辑时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("商户手续费优惠营销活动编辑时接口调用失败");
//        }
//
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("商户手续费优惠营销活动编辑时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("商户手续费优惠营销活动编辑时失败:" + res.getResult().getRespDesc());
//        }
//    }
//
//    /**
//     * 转换编辑的对象
//     *
//     * @param entity
//     * @return
//     */
//    private EditMchntFeeDiscountMcDetailRequest getEditBean(CommissionInfo entity) {
//        EditMchntFeeDiscountMcDetailRequest bean = new EditMchntFeeDiscountMcDetailRequest();
//        MchntFeeDiscountMcInfoBean mcInfoBean = new MchntFeeDiscountMcInfoBean();
//        //请求报文参数
//        bean.setOprType(entity.getOprType());
//        bean.setQueryType(entity.getQueryType());
//        bean.setQueryRole(entity.getQueryRole());
//        mcInfoBean.setMcNo(entity.getMcNo());
//        mcInfoBean.setMcName(entity.getMcName());
//        mcInfoBean.setDepositMonNum(entity.getDepositMonNum());
//        mcInfoBean.setMcType("20");//营销活动类型
//        mcInfoBean.setMcStatus(entity.getMcStatus());
//        mcInfoBean.setNewMchntAmountType(entity.getNewMchntAmountType());
//        //日期可能需要转换格式
//        if (StringUtils.isNotBlank(entity.getMcStartDate())) {
//            mcInfoBean.setMcStartDate(entity.getMcStartDate().replaceAll("-", ""));
//        }
//        if (StringUtils.isNotBlank(entity.getMcEndDate())) {
//            mcInfoBean.setMcEndDate(entity.getMcEndDate().replaceAll("-", ""));
//        }
//        String discountPeriod = null;
//        String stockMchntFlag = entity.getStockMchntFlag(); //存量商户达标条件
//        String stockMchntType = entity.getStockMchntType(); //存量商户支持类型
//        if ("1".equals(stockMchntFlag)) {
//            // 如果指定商户和商圈都未选择，stockMchntFlag上送2-支持选定机构内所有有效商户
//            if (StringUtils.isBlank(entity.getMerchantList()) &&
//                    StringUtils.isBlank(entity.getCircleList())) {
//                mcInfoBean.setStockMchntFlag("2");
//            } else {
//                mcInfoBean.setStockMchntFlag(stockMchntFlag);
//            }
//            mcInfoBean.setStockMchntType(stockMchntType);
//            if ("1".equals(stockMchntType)) {
//                mcInfoBean.setEffectiveLimit(entity.getEffectiveLimitTranNum());
//                discountPeriod = entity.getDiscoutPeriodTranNum();
//            } else if ("2".equals(stockMchntType)) {
//                mcInfoBean.setEffectiveLimit(entity.getEffectiveLimitTranMoney());
//                discountPeriod = entity.getDiscoutPeriodTranMoney();
//            } else if ("3".equals(stockMchntType)) {
//                mcInfoBean.setEffectiveLimit("0");
//                discountPeriod = entity.getDiscoutPeriodFeeMoney();
//            } else {
//                mcInfoBean.setEffectiveLimit("0");
//            }
//        } else {
//            mcInfoBean.setStockMchntFlag("0");
//        }
//
//        String newMchntFlag = entity.getNewMchntFlag(); //新增商户支持标志
//        if ("1".equals(newMchntFlag)) {
//            mcInfoBean.setNewMchntFlag(newMchntFlag);
//            mcInfoBean.setNewMchntPeriod(entity.getNewMchntPeriod());
//            mcInfoBean.setNewMchntAmountLimit(entity.getNewMchntAmountLimit());
//            mcInfoBean.setPostponeFlag("1".equals(entity.getPostponeFlag()) ? "1" : "0");
//        } else {
//            mcInfoBean.setNewMchntFlag("0");
//        }
//        String beforeFlag = (StringUtils.isEmpty(entity.getBeforeFlag()) || "1".equals(entity.getBeforeFlag())) ? "1" : "0";//达标前手续费优惠规则
//        String afterFlag = entity.getAfterFlag();//达标后手续费优惠规则
//        mcInfoBean.setBeforeFlag(beforeFlag);
//        mcInfoBean.setAfterFlag(afterFlag);
//        if ("1".equals(beforeFlag) && "0".equals(afterFlag)) {
//            mcInfoBean.setBudget("0");
//        } else {
//            mcInfoBean.setBudget(entity.getBudget());
//        }
//        String statPeriod = entity.getStatPeriod();
//        if (StringUtils.isBlank(statPeriod)) {
//            mcInfoBean.setTerminationFlag("0");
//            mcInfoBean.setStatPeriod("0");
//            mcInfoBean.setQuantityLimit("0");
//            mcInfoBean.setAmountLimit("0");
//            mcInfoBean.setFeeLimit("0");
//        } else {
//            mcInfoBean.setTerminationFlag("1");
//            mcInfoBean.setStatPeriod(entity.getStatPeriod());
//            mcInfoBean.setQuantityLimit(entity.getQuantityLimit());
//            mcInfoBean.setAmountLimit(entity.getAmountLimit());
//            mcInfoBean.setFeeLimit(entity.getFeeLimit());
//        }
//        mcInfoBean.setBudgetRechargeMethod("1"); //预算充值方式
//        mcInfoBean.setAuditStatus(entity.getAuditStatus());
//        User user = AuthContextHolder.findAuthUser();
//        mcInfoBean.setInstId(user.getInstId());//机构编码
//        if (StringUtils.isBlank(entity.getMcNo())) {
//            //为空表示新增,不为空表示修改
//            mcInfoBean.setOprId(user.getId());//创建人
//            mcInfoBean.setCreateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT));
//        } else {
//            mcInfoBean.setOprId(entity.getOprId());//创建人
//            mcInfoBean.setCreateTime(entity.getCreateTime());
//            mcInfoBean.setLastOprId(user.getId());
//            mcInfoBean.setUpdateTime(DateUtils.formatDate(new Date(), DateUtils.DEFAULT_TIME_FORMAT));
//        }
//        //活动支持的商户类型
//        mcInfoBean.setAvySprtMrctTyp(entity.getSupportTypeStr());
//        bean.setMcInfoObj(mcInfoBean);
//        //机构信息
//        String orgInfoJson = StringEscapeUtils.unescapeHtml4(entity.getOrgInfoList());
//        List<McOrgInfoBean> orgInfoList = JSONArray.parseArray(orgInfoJson, McOrgInfoBean.class);
//        bean.setOrgInfoList(orgInfoList);
//        //商户信息
//        List<McMchntInfoBean> mchntInfoList = new ArrayList<>();
//        if (StringUtils.isNotBlank(entity.getMerchantList())) {
//            String merchantJson = StringEscapeUtils.unescapeHtml4(entity.getMerchantList());
//            List<McMchntInfoBean> merchantList = JSONArray.parseArray(merchantJson, McMchntInfoBean.class);
//            mchntInfoList.addAll(merchantList);
//        }
//        if (StringUtils.isNotBlank(entity.getCircleList())) {
//            String circleJson = StringEscapeUtils.unescapeHtml4(entity.getCircleList());
//            List<McMchntInfoBean> circletList = JSONArray.parseArray(circleJson, McMchntInfoBean.class);
//            mchntInfoList.addAll(circletList);
//        }
//        bean.setMchntInfoList(mchntInfoList);
//        //规则信息
//        if ("1".equals(stockMchntFlag) && StringUtils.isNotBlank(entity.getRuleInfoList())) {
//            String ruleInfoJson = StringEscapeUtils.unescapeHtml4(entity.getRuleInfoList());
//            List<MchntFeeDiscountRuleInfoBean> ruleInfoList = JSONArray.parseArray(ruleInfoJson, MchntFeeDiscountRuleInfoBean.class);
//            int i = 1;
//            for (MchntFeeDiscountRuleInfoBean ruleInfoBean : ruleInfoList) {
//                ruleInfoBean.setRuleIndex(String.valueOf(i));
//                ruleInfoBean.setDiscountPeriod(discountPeriod);
//                if (i == ruleInfoList.size() && StringUtils.isBlank(ruleInfoBean.getCriteriaCelling())) {
//                    ruleInfoBean.setCriteriaCelling("99999999999999999.99");
//                }
//                i++;
//            }
//            bean.setRuleInfoList(ruleInfoList);
//        }
//        //产品信息
//        List<McProductInfoBean> productInfoList = new ArrayList<>();
//        String[] onLineProduce = entity.getOnLineProduce();
//        String[] upLineProduce = entity.getUpLineProduce();
//        if (null != onLineProduce && onLineProduce.length > 0) {
//            for (String str : onLineProduce) {
//                McProductInfoBean infoBean = new McProductInfoBean();
//                infoBean.setBizProdCode(str);
//                productInfoList.add(infoBean);
//            }
//        }
//        if (null != upLineProduce && upLineProduce.length > 0) {
//            for (String str : upLineProduce) {
//                McProductInfoBean infoBean = new McProductInfoBean();
//                infoBean.setBizProdCode(str);
//                productInfoList.add(infoBean);
//            }
//        }
//        bean.setProductInfoList(productInfoList);
//        return bean;
//    }
//
//    /**
//     * 进行中活动新增商户
//     *
//     * @param entity
//     */
//    public OperationResult addmchntInfos(CommissionAddMchntRequest entity) {
//        AddMchntForToClientMcRequest reqDto = new AddMchntForToClientMcRequest();
//        try{
//            reqDto = getAddBean(entity);
//        }catch (ServiceException se){
//            return OperationResult.buildFailureResult("请输入要新增的商户");
//        }
//
//        User user = AuthContextHolder.findAuthUser();
//        String orgCode = getOrgCode(user.getOrgCode());
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum(MompTxnNumEnum.TOCLIEENT_MC_ADD.getType());
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + MompTxnNumEnum.TOCLIEENT_MC_ADD.getType() + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//
//        Result<AddMchntForToClientMcResponse> res = new Result<>();
//        try {
//            log.info("进行中的活动添加商户 请求报文：{}", JSON.toJSONString(reqDto));
//            res = editMcDetailService.addMchntForToClientMc(reqDto);
//            log.info("进行中的活动添加商户 应答报文：{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("进行中的活动添加商户时系统异常:[{}]", e);
//            //throw new ServiceException("进行中的活动添加商户时系统异常,请联系管理员");
//            return OperationResult.buildFailureResult("进行中的活动添加商户时接口调用失败");
//        }
//        if (null == res || null == res.getResult()) {
//            log.error("进行中的活动添加商户时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            //throw new ServiceException("进行中的活动添加商户时接口调用失败");
//            return OperationResult.buildFailureResult("进行中的活动添加商户时接口调用失败");
//        }
//
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("进行中的活动添加商户时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            //throw new ServiceException("进行中的活动添加商户时失败:" + res.getResult().getRespDesc());
//            return OperationResult.buildFailureResult("进行中的活动添加商户时失败:" + res.getResult().getRespDesc());
//        }
//        List<McMchntInfoBean> mchntInfoList = reqDto.getMchntInfoList();
//        String oprType = "";
//        for(McMchntInfoBean mcMchntInfoBean : mchntInfoList){
//            oprType += mcMchntInfoBean.getOprType();
//        }
//        if(oprType.contains("I") && oprType.contains("D")){
//            return OperationResult.buildSuccessResult("进行中的活动新增商户修改成功");
//        }
//        return OperationResult.buildSuccessResult("进行中的活动新增商户修改成功");
//    }
//
//    /**
//     * 转换进行中活动新增商户的对象
//     *
//     * @param entity
//     * @return
//     */
//    private AddMchntForToClientMcRequest getAddBean(CommissionAddMchntRequest entity) {
//        AddMchntForToClientMcRequest bean = new AddMchntForToClientMcRequest();
//        bean.setMcNo(entity.getMcNo());
//        bean.setMcType(entity.getMcType());
//        bean.setQueryType(entity.getQueryType());
//        bean.setQueryRole(entity.getQueryRole());
//        //商户信息
//        //新增商户之后的商户商圈
//        List<McMchntInfoBean> mchntInfoList = new ArrayList<>();
//        if (StringUtils.isNotBlank(entity.getMerchantList())) {
//            String merchantJson = StringEscapeUtils.unescapeHtml4(entity.getMerchantList());
//            List<McMchntInfoBean> merchantList = JSONArray.parseArray(merchantJson, McMchntInfoBean.class);
//            mchntInfoList.addAll(merchantList);
//        }
//        if (StringUtils.isNotBlank(entity.getCircleList())) {
//            String circleJson = StringEscapeUtils.unescapeHtml4(entity.getCircleList());
//            List<McMchntInfoBean> circletList = JSONArray.parseArray(circleJson, McMchntInfoBean.class);
//            mchntInfoList.addAll(circletList);
//        }
//        //做个判断,entity.getMchntInfoOldList() 为空，说明是对客类营销活动新增，不允许删除原有的商户信息
//        if (StringUtils.isBlank(entity.getMchntInfoOldList())) {
//            bean.setMchntInfoList(mchntInfoList);
//            return bean;
//        }
//        String mchOldJson = StringEscapeUtils.unescapeHtml4(entity.getMchntInfoOldList());
//        //新增商户之前的商户商圈
//        List<McMchntInfoBean> mchOldList = JSONArray.parseArray(mchOldJson, McMchntInfoBean.class);
//
//        // 增加的商户
//        List<McMchntInfoBean> addList = new ArrayList<>();
//        // 删除的商户
//        List<McMchntInfoBean> delList = new ArrayList<>();
//        Map<String, McMchntInfoBean> oldObjMap = new HashMap<>();
//        for (McMchntInfoBean mcMchntInfoBean : mchOldList) {
//            oldObjMap.put(mcMchntInfoBean.getMchntNo(), mcMchntInfoBean);
//        }
//        for (McMchntInfoBean mcMchntInfoBean : mchntInfoList) {
//            if (oldObjMap.containsKey(mcMchntInfoBean.getMchntNo())) {
//                oldObjMap.remove(mcMchntInfoBean.getMchntNo());
//            } else {
//                mcMchntInfoBean.setOprType("I");
//                addList.add(mcMchntInfoBean);
//            }
//        }
//        for (String mchntNo : oldObjMap.keySet()) {
//            McMchntInfoBean mcMchntInfoBean = oldObjMap.get(mchntNo);
//            mcMchntInfoBean.setOprType("D");
//            delList.add(oldObjMap.get(mchntNo));
//        }
//
//        if (CollectionUtils.isEmpty(addList) && CollectionUtils.isEmpty(delList)) {
//            throw new ServiceException("请输入要新增的商户或者商圈");
//        }
//        if (null == bean.getMchntInfoList()) {
//            bean.setMchntInfoList(new ArrayList<>());
//        }
//        bean.getMchntInfoList().addAll(addList);
//        bean.getMchntInfoList().addAll(delList);
//        return bean;
//
//    }
//
//    /**
//     * 差集：删除左边集合中在右边集合存在的元素并返回
//     *
//     * @param left
//     * @param right
//     * @return
//     */
//    private List<McMchntInfoBean> removeAll(List<McMchntInfoBean> left, List<McMchntInfoBean> right) {
//        List<McMchntInfoBean> res = new LinkedList<>(left);
//        Set<String> set = new HashSet<>();
//        //将no存放到set
//        for (McMchntInfoBean item : right) {
//            set.add(item.getMchntNo());
//        }
//        //迭代器遍历list
//        Iterator<McMchntInfoBean> iter = res.iterator();
//        while (iter.hasNext()) {
//            McMchntInfoBean item = iter.next();
//            //如果set中包含id则remove
//            if (set.contains(item.getMchntNo()) && !"I".equalsIgnoreCase(item.getOprType())) {
//                iter.remove();
//            }
//        }
//        return res;
//    }
//
//    /**
//     * 根据活动编号查询活动详情
//     *
//     * @param mcNo
//     * @return
//     */
//    public QueryMchntFeeDiscountMcDetailInfoResponse getDetailData(String mcNo, String queryType, String queryRole) {
//        QueryMchntFeeDiscountMcDetailInfoRequest reqDto = new QueryMchntFeeDiscountMcDetailInfoRequest();
//        User user = AuthContextHolder.findAuthUser();
//        String orgCode = getOrgCode(user.getOrgCode());
//        reqDto.setMcNo(mcNo);
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//        reqDto.setQueryType(queryType);
//        reqDto.setQueryRole(queryRole);
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum("M00MO012");
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + orgCode + "M00MO012" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//
//        Result<QueryMchntFeeDiscountMcDetailInfoResponse> res;
//        try {
//            log.info("查询营销活动详情 请求报文：{}", JSON.toJSONString(reqDto));
//            res = detailInfoService.queryMchntFeeDiscountMcDetailInfo(reqDto);
//            log.info("查询营销活动详情 应答报文：{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("查询营销活动详情时系统异常:[{}]", e);
//            throw new ServiceException("查询营销活动详情时系统异常,请联系管理员");
//        }
//
//        if (null == res || null == res.getResult()) {
//            log.error("查询营销活动详情时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("查询营销活动详情时接口调用失败");
//        }
//
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("查询营销活动详情时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("查询营销活动详情时失败:" + res.getResult().getRespDesc());
//        }
//
//        return res.getResult();
//    }
//

//

//
//    /**
//     * 商户手续费发布
//     *
//     * @param entity
//     */
//    public void publishMchntFeeDiscountMc(Model model, CommissionPublishRequest entity, String msg) {
//        PublishMchntFeeDiscountMcRequest reqDto = getPublishBean(entity);
//        User user = AuthContextHolder.findAuthUser();
//        String skipPub = "";
//        // 调用营销打款接口
//        MchntFeeDiscountMcInfoBean respBean = this.setModel(model, entity.getMcNo(), entity.getQueryType(), entity.getQueryRole());
//        DataDict dict=dataDictService.findByPrimaryKeyAndInstId("skipPub",user.getInstId());
//        if(Common.isNotBlank(dict)){
//            skipPub = dict.getPrimaryValue();
//        }
//        // 达标后的交易通过手续费实时优惠营销,勾选了此选项，预算为0，故无需调用打款接口
//        if (!"1".equals(skipPub)
//                && StringUtils.isNotBlank(respBean.getBudget()) &&
//                !"0".equals(respBean.getBudget())
//                && "0".equals(entity.getOprType())) {
//            OperationResult result = customerMarketService.mompPayment(entity.getMcNo(), reqDto.getAcctInfoObk(), user, respBean.getBudget());
//            if (!OperationResult.SUCCESS.equals(result.getCode())) {
//                log.error("调用营销打款接口失败");
//                throw new ServiceException("调用营销打款接口失败，请联系管理员");
//            }
//        }
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum("M00MO015");
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + user.getOrgCode() + "M00MO015" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//
//        Result<PublishMchntFeeDiscountMcResponse> res = new Result<>();
//        try {
//            log.info("商户手续费营销活动" + msg + " 请求报文：{}", JSON.toJSONString(reqDto));
//            res = publishMcService.publishMchntFeeDiscountMc(reqDto);
//            log.info("商户手续费营销活动" + msg + "  应答报文：{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("商户手续费营销活动" + msg + "时系统异常:[{}]", e);
//            throw new ServiceException("商户手续费营销活动" + msg + "时系统异常,请联系管理员");
//        }
//
//        if (null == res || null == res.getResult()) {
//            log.error("商户手续费营销活动" + msg + "时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("商户手续费营销活动" + msg + "时接口调用失败");
//        }
//
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("商户手续费营销活动" + msg + "时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("商户手续费营销活动" + msg + "时失败:" + res.getResult().getRespDesc());
//        }
//    }
//
//    /**
//     * 商户手续费发布
//     *
//     * @param entity
//     */
//    public void shutDownMchntFeeDiscountMc(Model model, CommissionPublishRequest entity, String msg) {
//        PublishMchntFeeDiscountMcRequest reqDto = getPublishBean(entity);
//        User user = AuthContextHolder.findAuthUser();
//        //设置入参
//        reqDto.setQueryId(user.getId());
//        reqDto.setQueryOrgId(user.getOrgCode());
//
//        //设置报文头
//        Header header = new Header();
//        header.setVersion(BusinessContainer.BOMP_VERSION);
//        header.setTransDate(CommonUtils.getCurrentDate("yyyyMMdd"));
//        header.setTransTime(CommonUtils.getCurrentDate("HHmmss"));
//        header.setTxnNum("M00MO015");
//        header.setBizType(BusinessContainer.IGAS_DEFAULT_BIZ_TYPE);
//        header.setInstId(user.getInstId());
//        header.setSrcSysId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setChanlId(BusinessContainer.MOMP_SRC_SYS_ID);
//        header.setTraceNo(user.getInstId().substring(0, 3) + user.getOrgCode() + "M00MO015" + DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS"));
//        reqDto.setHeader(header);
//
//        Result<PublishMchntFeeDiscountMcResponse> res = new Result<>();
//        try {
//            log.info("商户手续费营销活动" + msg + " 请求报文：{}", JSON.toJSONString(reqDto));
//            res = publishMcService.publishMchntFeeDiscountMc(reqDto);
//            log.info("商户手续费营销活动" + msg + "  应答报文：{}", JSON.toJSONString(res));
//        } catch (Exception e) {
//            log.error("商户手续费营销活动" + msg + "时系统异常:[{}]", e);
//            throw new ServiceException("商户手续费营销活动" + msg + "时系统异常,请联系管理员");
//        }
//
//        if (null == res || null == res.getResult()) {
//            log.error("商户手续费营销活动" + msg + "时接口调用失败:result=[{}]", JSON.toJSONString(res));
//            throw new ServiceException("商户手续费营销活动" + msg + "时接口调用失败");
//        }
//
//        if (!BusinessContainer.BSPS_SUCCESS.equals(res.getResult().getRespCode())) {
//            log.error("商户手续费营销活动" + msg + "时失败:code=[{}],msg=[{}]", res.getResult().getRespCode(), res.getResult().getRespDesc());
//            throw new ServiceException("商户手续费营销活动" + msg + "时失败:" + res.getResult().getRespDesc());
//        }
//    }
//

//
//    /**
//     * 查询商户信息
//     *
//     * @param user
//     * @param request
//     * @param bompQueryService
//     * @param traceNo
//     * @return
//     */
//    public Map<String, Object> queryMcNoList(User user, MchntInfoListQueryRequest request, BompMchntQueryService bompQueryService, String traceNo) {
//        MchntInfoListQueryRequest req = new MchntInfoListQueryRequest();
//        int pageIndex = 0;
//        int pageSize = 50000;
//        req.setMchntNo(request.getMchntNo());
//        req.setMchntName(request.getMchntName());
//        req.setMchntArea(request.getMchntArea());
//        req.setPageIndex(pageIndex);
//        req.setPageSize(pageSize);
//        req.setMchntStatus(BompMchntStatusEnum.NORMAL.getType());
//        req.setUserId(user.getId());
//        MchntInfoListQueryResponse resp = bMchntBaseInfoService.mchntInfoListQuery(user.getInstId(), user, req, bompQueryService, traceNo);
//        Map<String, Object> maps = new HashMap<>();
//        if (Common.isNotBlank(resp)) {
//            List<MchntInfoBean> list = resp.getMchntInfoList();
//
//            if (CollectionUtils.isNotEmpty(list)) {
//                Map<String, String> map = new HashMap<>();
//                List<Object> rst = new ArrayList<>();
//                for (MchntInfoBean mchnt : list) {
//
//                    map = new HashMap<String, String>();
//                    map.put("id", mchnt.getMchntNo());
//                    map.put("name", mchnt.getMchntName());
//                    map.put("orgId", mchnt.getSignInstId());
//                    rst.add(map);
//                }
//                maps.put("results", rst);
//                maps.put("more", false);
//                maps.put("totalPage", resp.getTotalPage());
//                maps.put("totalRows", resp.getTotalRows());
//            }
//        }
//        return maps;
//    }
//
//    /**
//     * 校验是否是特殊费率商户
//     *
//     * @param user
//     * @param mchntNo
//     * @param bompQueryService
//     * @param traceNo
//     * @return
//     */
//    public Boolean checkFeeMchnt(User user,String mchntNo, BompMchntQueryService bompQueryService, String traceNo) {
//        MchntFeeListQueryRequest req = new MchntFeeListQueryRequest();
//        req.setMchntNo(mchntNo);
//        req.setUserId(user.getId());
//        MchntFeeListQueryResponse resp = this.mchntFeeListQuery(user.getInstId(), user, req, bompQueryService, traceNo);
//        boolean isFeeMchntFlag = false;
//        if (Common.isNotBlank(resp)) {
//            List<MchntFeeInfoBean> list = resp.getMchntFeeInfoBeanList();
//
//            if (CollectionUtils.isNotEmpty(list)) {
//                for (MchntFeeInfoBean mchnt : list) {
//                    if ("0".equals(mchnt.getFeeInputMode())) {
//                        isFeeMchntFlag = true;
//                    }
//                }
//            }
//        }
//        return isFeeMchntFlag;
//    }
//
//    /**
//     * 商户费率列表查询
//     *
//     * */
//    public MchntFeeListQueryResponse mchntFeeListQuery(String instId, User user, MchntFeeListQueryRequest req, BompMchntQueryService bompQueryService, String traceNo) throws ServiceException {
//        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.mchntFeeListQuery.getType(), instId,null));
//        req.setUserId(user.getId());
//
//        try {
//            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易请求报文：" + JSON.toJSONString(req));
//
//            cc.rengu.igas.bomp.facade.result.Result<MchntFeeListQueryResponse> response = bompQueryService.mchntFeeListQuery(req);
//            log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
//            if (response.isSuccess()) {
//                MchntFeeListQueryResponse resp = response.getResult();
//                // 返回码：00000000-进件成功，其他均视为失败
//                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
//                    log.info("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易成功");
//                    return resp;
//                } else {
//                    log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易失败");
//                    return null;
//                }
//            } else {
//                log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易没有获得返回信息");
//                return null;
//            }
//        } catch (Exception e) {
//            // TODO: handle exception
//            log.error("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
//            throw new ServiceException("法人行[" + user.getInstId() + "],用户标识[" + req.getUserId() + "],商户号[" + req.getMchntNo() + "]" + BompTxnNumEnum.mchntFeeListQuery.getDesc() + "交易出现异常", e);
//        }
//    }
//
//    public MchntFeeDiscountMcInfoBean setModel(Model model, String mcNo, String queryType, String queryRole) {
//        QueryMchntFeeDiscountMcDetailInfoResponse respBean = this.getDetailData(mcNo, queryType, queryRole);
//        MchntFeeDiscountMcInfoBean entity = respBean.getMcInfoObj();
//        if ("1".equals(entity.getBeforeFlag()) && "0".equals(entity.getAfterFlag())) {
//            entity.setBudget(null);
//        }
//        if ("0".equals(entity.getStatPeriod())) {
//            entity.setQuantityLimit(null);
//            entity.setAmountLimit(null);
//            entity.setFeeLimit(null);
//        }
//        Date start = DateUtils.parseDate(entity.getMcStartDate(), DateUtils.FORMAT_YYYYMMDD);
//        Date end = DateUtils.parseDate(entity.getMcEndDate(), DateUtils.FORMAT_YYYYMMDD);
//        entity.setMcStartDate(DateUtils.formatDate(start, DateUtils.DEFAULT_DATE_FORMAT));
//        entity.setMcEndDate(DateUtils.formatDate(end, DateUtils.DEFAULT_DATE_FORMAT));
//        // 详情时特殊处理：前端使用的checkbox只有0和1。当存量商户达标条件为2-支持选定机构内所有有效商户时 也设置为checkbox=1
//        if ("2".equals(entity.getStockMchntFlag())) {
//            entity.setStockMchntFlag("1");
//        }
//        model.addAttribute("entity", entity);
//        List<String> orgList = new ArrayList<>();
//        List<McOrgInfoBean> orgInfoList = respBean.getOrgInfoList();
//        for (McOrgInfoBean orgBean : orgInfoList) {
//            orgList.add(orgBean.getOrgId());
//        }
//        model.addAttribute("orgList", JSON.toJSONString(orgList));
//        List<MchntFeeDiscountRuleInfoBean> ruleInfoList = respBean.getRuleInfoList();
//        if (null != ruleInfoList && ruleInfoList.size() > 0) {
//            model.addAttribute("discountPeriod", ruleInfoList.get(0).getDiscountPeriod());
//        }
//        model.addAttribute("rules", JSON.toJSONString(ruleInfoList));
//        List<McMchntInfoBean> mchntInfoList = respBean.getMchntInfoList();
//        List<McMchntInfoBean> merchantList = new ArrayList<>();
//        List<McMchntInfoBean> circleList = new ArrayList<>();
//        if(CollectionUtils.isNotEmpty(mchntInfoList)){
//            for (McMchntInfoBean infoBean : mchntInfoList) {
//                if ("0".equals(infoBean.getMchntType())) {
//                    merchantList.add(infoBean);
//                } else if ("1".equals(infoBean.getMchntType())) {
//                    circleList.add(infoBean);
//                } else {
//                    log.info("CommissionMarketService:setModel");
//                }
//            }
//        }
//        model.addAttribute("mchntInfoOldList", JSON.toJSONString(mchntInfoList));
//        model.addAttribute("merchantList", merchantList);
//        model.addAttribute("circleList", circleList);
//
//        //线上、线下营销产品
//        List<McProductInfoBean> productInfoList = respBean.getProductInfoList();
//        List<String> lineProducekList = new ArrayList<>();
//        if(CollectionUtils.isNotEmpty(productInfoList)) {
//            for (McProductInfoBean infoBean : productInfoList) {
//                lineProducekList.add(infoBean.getBizProdCode());
//            }
//        }
//
//        model.addAttribute("lineProducekList", JSON.toJSONString(lineProducekList));
//
//        return entity;
//    }



}
